package com.fun_ordering.controller;

import com.fun_ordering.components.ApiResponse;
import com.fun_ordering.components.PageResult;
import com.fun_ordering.pojo.FoStatus;
import com.fun_ordering.service.FoStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * controller
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/foStatus")
public class FoStatusController {

	@Autowired
	private FoStatusService foStatusService;
	
	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<FoStatus> findAll(){
		return foStatusService.findAll();
	}
	
	
	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult findPage(int page, int rows){
		return foStatusService.findPage(page, rows);
	}
	
	/**
	 * 增加
	 * @param foStatus
	 * @return
	 */
	@RequestMapping("/add")
	public ApiResponse add(@RequestBody FoStatus foStatus){
		try {
			foStatusService.add(foStatus);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}
	
	/**
	 * 修改
	 * @param foStatus
	 * @return
	 */
	@RequestMapping("/update")
	public ApiResponse update(@RequestBody FoStatus foStatus){
		try {
			foStatusService.update(foStatus);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}	
	
	/**
	 * 获取实体
	 * @param
	 * @return
	 */
	@RequestMapping("/findOne")
	public FoStatus findOne(Integer statusId){
		return foStatusService.findOne(statusId);		
	}
	
	/**
	 * 批量删除
	 * @param
	 * @return
	 */
	@RequestMapping("/delete")
	public ApiResponse delete(Integer [] statusIds){
		try {
			foStatusService.delete(statusIds);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}
	
	/**
	 * 查询+分页
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody FoStatus foStatus, int page, int rows  ){
		return foStatusService.findPage(foStatus, page, rows);		
	}
	
}
